# coding = utf-8
import xlrd
from xlutils.copy import copy
# excel =xlrd.open_workbook('../config/case.xlsx')
#
# data = excel.sheets()[0]
# print(data.nrows)  # 获取行数
# print(data.cell(4, 5).value)  # 从0开始算，第四行第五列

class OperaExcel:
    def __init__(self, file_path=None, i=None):
        if file_path == None:
            self.file_path = '../config/case.xls'
        else:
            self.file_path = file_path
        if i == None:
            i = 0
        self.excel = self.get_excel()
        self.data = self.get_sheets(i)

    def get_excel(self):
        excel = xlrd.open_workbook(self.file_path)
        return excel
    def get_sheets(self, i):
        table =self.excel.sheets()[i]
        return table
    def get_lines(self):
        '''获取Excel行数'''
        lines = self.data.nrows
        return lines

    def get_cell(self, row, cell):
        value = self.data.cell(row, cell).value
        return value
    def write_value(self,row,value):
        read_value = self.excel
        write_data = copy(read_value)
        write_save = write_data.get_sheet(0)
        write_save.write(row,8,value)
        write_data.save(self.file_path)



if __name__ == '__main__':
    opera = OperaExcel()
    print(opera.get_lines())
    print(opera.write_value(6,'pass'))
#     print(opera.get_lines())
#     print(opera.get_cell(4, 5))